package prostagra;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;

public abstract class Gra extends Thread
{

    private boolean isRunning;
    protected int szerokosc;
    protected int wysokosc;

    
    public final void setup()
    {
        init();
    }
    
    public void init(){}
    

    public final Image readImage(String name)
    {
        return new ImageIcon(name).getImage();
    }

    public int getSzerokosc()
    {
        return szerokosc;
    }

    public void setSzerokosc(int szerokosc)
    {
        this.szerokosc = szerokosc;
    }

    public int getWysokosc()
    {
        return wysokosc;
    }

    public void setWysokosc(int wysokosc)
    {
        this.wysokosc = wysokosc;
    }

    /**
    Runs through the game loop until stop() is called.
     */
    public void gameLoop()
    {
        isRunning = true;
        long startTime = System.currentTimeMillis();
        long currTime = startTime;

        while (isRunning)
        {
            long elapsedTime =
                    System.currentTimeMillis() - currTime;
            currTime += elapsedTime;

            // update
            update(elapsedTime);
        }
    }

    @Override
    public void run()
    {
        gameLoop();
    }

    /**
     * Updates the state of the game/animation based on the
     * amount of elapsed time that has passed.
     * @param elapsedTime 
     */
    public abstract void update(long elapsedTime);

    /**
     * Draws to the screen. Subclasses must override this
     * method.
     * @param g 
     */
    public abstract void draw(Graphics2D g);
    
    

    public void mousePressed(MouseEvent e)
    {
    }

    public void mouseClicked(MouseEvent e)
    {
    }

    public void mouseReleased(MouseEvent e)
    {
    }

    public void mouseEntered(MouseEvent e)
    {
    }

    public void mouseExited(MouseEvent e)
    {
    }

    public void keyPressed(KeyEvent e)
    {
    }

    public void keyTyped(KeyEvent e)
    {
    }

    public void keyReleased(KeyEvent e)
    {
    }
}
